package com.ysq.www.api.work.service.impl;

import com.ysq.www.api.work.entity.Apply;
import com.ysq.www.api.work.entity.Approve;
import com.ysq.www.api.work.mapper.ApplyMapper;
import com.ysq.www.api.work.mapper.ApproveMapper;
import com.ysq.www.api.work.service.IApplyService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ysq.www.common.result.ResultMsg;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * <p>
 * 入会申请表 服务实现类
 * </p>
 *
 * @author dql
 * @since 2020-08-11
 */
@Slf4j
@Service
public class ApplyServiceImpl extends ServiceImpl<ApplyMapper, Apply> implements IApplyService {

    @Autowired
    private ApplyMapper applyMapper;

    @Autowired
    private ApproveMapper approveMapper;

    @Override
    public ResultMsg addApply(Apply apply) {
        //新增入会申请
        apply.setCreateTime(new Date());
        boolean save = this.save(apply);
        if (save){
            Approve ae = new Approve();
            ae.setType(1);
            ae.setCheckId(1);//审批人id 待定
            ae.setContentId(apply.getId());
            ae.setSupperId(0);//上级审批人id
            ae.setLowerId(0);//下级审批人id
            ae.setCheckStatus(0);
            ae.setCreateTime(new Date());
            ae.setStatus(0);
            approveMapper.insert(ae);
            return ResultMsg.INSERT_SUCCESS.setNewMsg("提交处理成功");
        }else return ResultMsg.INSERT_ERROR.setNewMsg("提交处理失败");
    }
}
